<template>
  <div class="mod-biddingrule__biddingrule">
    <el-form :inline="true" :model="state.dataForm" @keyup.enter="state.getDataList()">
      <el-form-item>
        <el-input v-model="state.dataForm.purchaseProjectCode" placeholder="项目编号" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="state.dataForm.purchaseProjectName" placeholder="项目名称" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="state.getDataList()">查询</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="state.hasPermission('biddingrule:biddingrule:save') && state.dataForm.purchaseProjectId" type="primary" @click="addOrUpdateHandle()">新增</el-button>
      </el-form-item>
<!--      <el-form-item>-->
<!--        <el-button v-if="state.hasPermission('biddingrule:biddingrule:delete')" type="danger" @click="state.deleteHandle()">删除</el-button>-->
<!--      </el-form-item>-->
<!--      <el-form-item>-->
<!--        <el-button v-if="state.hasPermission('biddingrule:biddingrule:export')" type="info" @click="state.exportHandle()">导出</el-button>-->
<!--      </el-form-item>-->
    </el-form>
    <el-table v-loading="state.dataListLoading" :data="state.dataList" border @selection-change="state.dataListSelectionChangeHandle" style="width: 100%">
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
              <el-table-column prop="purchaseProjectName" label="项目名称" header-align="center" align="center"></el-table-column>
              <el-table-column prop="purchaseProjectCode" label="项目编号" header-align="center" align="center"></el-table-column>
              <el-table-column prop="biddingStartTime" label="竞价开始时间" header-align="center" align="center" width = "160"></el-table-column>
              <el-table-column prop="biddingEndTime" label="竞价结束时间" header-align="center" align="center" width = "160"></el-table-column>
              <el-table-column prop="status" label="是否启用" header-align="center" align="center">
                <template v-slot="scope">
                  {{ state.getDictLabel("is_or_no", scope.row.status) }}
                </template>
              </el-table-column>
<!--              <el-table-column prop="isCutPriceRange" label="是否设置降价幅" header-align="center" align="center"></el-table-column>-->
<!--              <el-table-column prop="cutPriceRange" label="降价幅度，单位：元（当 is_cut_price_range 为 1 时有效）" header-align="center" align="center"></el-table-column>-->
<!--              <el-table-column prop="isDelayOffer" label="是否延迟报价" header-align="center" align="center">-->
<!--                <template v-slot="scope">-->
<!--                  {{ state.getDictLabel("is_or_no", scope.row.isDelayOffer) }}-->
<!--                </template>-->
<!--              </el-table-column>-->
<!--              <el-table-column prop="delayTime" label="延迟时间" header-align="center" align="center"></el-table-column>-->
<!--              <el-table-column prop="delayNumber" label="延迟次数" header-align="center" align="center"></el-table-column>-->
<!--              <el-table-column prop="createUser" label="项目创建人" header-align="center" align="center"></el-table-column>-->
<!--              <el-table-column prop="createTime" label="项目创建时间，格式：YYYY-MM-DD HH:MM:SS" header-align="center" align="center"></el-table-column>-->
<!--              <el-table-column prop="updateUser" label="最后更新人" header-align="center" align="center"></el-table-column>-->
<!--              <el-table-column prop="updateTime" label="最后更新时间，格式：YYYY-MM-DD HH:MM:SS" header-align="center" align="center"></el-table-column>-->
            <el-table-column label="操作" fixed="right" header-align="center" align="center" width="180">
        <template v-slot="scope">
          <el-button  type="primary" link @click="detailHandle(scope.row.biddingRuleId)">详情</el-button>
          <el-button v-if="state.hasPermission('biddingrule:biddingrule:update')" type="primary" link @click="addOrUpdateHandle(scope.row.biddingRuleId)">修改</el-button>
          <el-button v-if="state.hasPermission('biddingrule:biddingrule:delete')" type="primary" link @click="state.deleteHandle(scope.row.biddingRuleId)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination :current-page="state.page" :page-sizes="[10, 20, 50, 100]" :page-size="state.limit" :total="state.total" layout="total, sizes, prev, pager, next, jumper" @size-change="state.pageSizeChangeHandle" @current-change="state.pageCurrentChangeHandle"> </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update ref="addOrUpdateRef" @refreshDataList="state.getDataList">确定</add-or-update>
    <detail ref="detailRef" @refreshDataList="state.getDataList">确定</detail>
  </div>
</template>

<script lang="ts" setup>
import useView from "@/hooks/useView";
import { reactive, ref, toRefs } from "vue";
import AddOrUpdate from "./biddingrule-add-or-update.vue";
import detail from "./biddingrule-detail.vue";

const props = defineProps({
  purchaseProjectId: {
    type: String,
    required: true
  },
  purchaseProjectCode: {
    type: String,
    required: true
  }
});

const view = reactive({
  deleteIsBatch: true,
  getDataListURL: "/biddingrule/biddingrule/page",
  getDataListIsPage: true,
  exportURL: "/biddingrule/biddingrule/export",
  deleteURL: "/biddingrule/biddingrule",
  dataForm: {
    purchaseProjectId: props.purchaseProjectId,
    purchaseProjectCode: props.purchaseProjectCode
  }
});

const state = reactive({ ...useView(view), ...toRefs(view) });

const addOrUpdateRef = ref();
const addOrUpdateHandle = (id?: number) => {
  addOrUpdateRef.value.dataForm.purchaseProjectId = props.purchaseProjectId;
  addOrUpdateRef.value.dataForm.purchaseProjectCode = props.purchaseProjectCode;
  addOrUpdateRef.value.init(id);
};

const detailRef = ref();
const detailHandle = (id?: number) => {
  detailRef.value.init(id);
};
</script>
